home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 8.0 KB | 222 lines | [TEXT/MPS ] |
- // UMenuView.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UMENUVIEW__
- #define __UMENUVIEW__
-
- //----------------------------------------------------------------------------------------
- // Theory of Operation
- //
- // This is Larry Rosenstein's excellent unit: UMenu, that supports an object-oriented way
- // of defining custom menus. Instead of writing a menu defproc, you simply create a
- // subtype of TMenuView and override certain methods. Not only is this easier to program,
- // but this unit takes care of some of the housekeeping that a menu defproc would normally
- // have to do.
- //
- // Changes since MacApp 2.0: You can now add subviews to your subclass of TMenuView, and
- // these subviews can have their own trackers. This is accomplished in HandleChooseMessage
- // by creating a dummy mouse down event and passing it to the TMenuView via the
- // HandleMouseDown method which then asks its subviews if any of them are interested in
- // the mousedown (eg. to create a tracker).
- //----------------------------------------------------------------------------------------
-
- // MacApp
-
- #ifndef __TOOLBOX__
- #include "Toolbox.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- // Toolbox
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
-
- //----------------------------------------------------------------------------------------
- // Constants
- //----------------------------------------------------------------------------------------
-
- const short kNoMenuItem = 0; // used to indicate that no item is
- // selected
-
-
- //----------------------------------------------------------------------------------------
- // MenuColors: a composite of the MCEntries
- //----------------------------------------------------------------------------------------
-
- struct MenuColors
- {
- CRGBColor itemColor; // the foreground color to draw the item
- // with (the color of the title if title
- // or menubar)
-
- CRGBColor backgroundColor; // the background color to draw the item
- // with (the color of the menubar if title
- // or menubar)
-
- CRGBColor markColor; // the foreground color to draw the mark
- // with (checkmarks, etc.)
-
- CRGBColor commandColor; // the foreground color to draw the
- // command key equivalent with (command-v
- // for paste, etc).
- };
-
- typedef MenuColors *MenuColorsPtr, **MenuColorsHandle;
-
-
- //----------------------------------------------------------------------------------------
- // TMenuView
- //----------------------------------------------------------------------------------------
-
- class TMenuView : public TView
- {
- MA_DECLARE_CLASS;
-
- protected:
- long fNextFlash; // Used internally
-
- public:
- MenuRef fMenuRef; // handle to menu itself
-
- long fFlashInterval; // Time (in ticks) between flashes of item
- // highlighting; default is -1 which means
- // only change highlighting w when item
- // changes
-
- Boolean fHighlighted; // True if an item is highlighted
-
- CRect fBorder; // Added to menuRect to get actual hit
- // CRect; FindItem will not be called if
- // the mouse is in the border.
-
-
-
- //------------------------------------------------------------------------------------
- // Initialization
- //------------------------------------------------------------------------------------
-
- TMenuView();
- // Constructor
- virtual ~TMenuView();
- // Destructor
-
- void IMenuView(ResNumber rsrcID, short menuWidth, short menuHeight);
- // IMenu reads the menu and sets up the MenuRef and defproc so that the Menu
- // Manager can communicate with the TMenuView object.
-
-
- //------------------------------------------------------------------------------------
- // Menu Definition; all these methods must be overridden
- //------------------------------------------------------------------------------------
-
- virtual short FindItem(CPoint hitPt);
- // This is called to convert a CPoint to an item number.
-
- virtual void Highlight(short whichItem, Boolean turnItOn);
- // Given an item number as returned by FindItem, this is called to highlight the
- // item. This will not be called with whichItem = kNoMenuItem.
-
-
- //------------------------------------------------------------------------------------
- // Other methods
- //------------------------------------------------------------------------------------
-
- virtual void GetMenuViewColors(ResNumber theMenu,
- short theItem,
- MenuColors& theMenuColors);
- // Called to get the appropriate menu colors for the menu and item. If the menu
- // and item are 0 then info is for the menubar. If item is 0 then info is for the
- // menu title. Attempts to return best guess at colors based on all available
- // info.
-
- virtual Boolean IsItemEnabled(short item);
- // Returns the enabled status of an item
-
- virtual void UpdateHighlight(short oldItem, short newItem);
- // Called to update menu item highlighting.
-
-
- //------------------------------------------------------------------------------------
- // Private
- //------------------------------------------------------------------------------------
-
- virtual void HandleDefproc(short message,
- MenuRef theMenu,
- CRect& menuRect,
- CPoint hitPt,
- short& whichItem);
- // This is called by the custom defproc; it does a CASE on the message and calls 1
- // or more of the methods above.
-
- virtual void HandleChooseMessage(short message,
- MenuRef theMenu,
- CRect& menuRect,
- CPoint hitPt,
- short& whichItem);
- // Called by the message dispatcher when a choose message has been sent
-
- virtual void HandleDrawMessage(short message,
- MenuRef theMenu,
- CRect& menuRect,
- CPoint hitPt,
- short& whichItem);
- // Called by the message dispatcher when a draw message has been sent
-
- virtual void HandleSizeMessage(short message,
- MenuRef theMenu,
- CRect& menuRect,
- CPoint hitPt,
- short& whichItem);
-
- virtual void HandlePopUpMessage(short message,
- MenuRef theMenu,
- CRect& menuRect,
- CPoint hitPt,
- short& whichItem);
-
-
- //------------------------------------------------------------------------------------
- // Focusing Methods
- //------------------------------------------------------------------------------------
-
- virtual Boolean Focus();
-
- virtual Boolean FocusOnSuperView();
-
- virtual Boolean IsActive(); // override
-
-
- //------------------------------------------------------------------------------------
- // Misc. Methods
- //------------------------------------------------------------------------------------
-
- virtual GrafPtr GetGrafPort();
-
- virtual Boolean IsShown(); // override
- };
-
-
- //----------------------------------------------------------------------------------------
- // Global functions declarations
- //----------------------------------------------------------------------------------------
-
- extern void InitUMenuView();
- // Call this at the start of your program, before creating any TMenuView objects. This
- // can signal Failure.
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations
- //----------------------------------------------------------------------------------------
-
- extern Boolean gTrackingInMenu;
-
- #endif
-